package model;

import java.sql.*;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import object.AccountDetail;
import object.AccountSignin;
import object.ReturnBool;
import tpInterface.IAccount;

/**
 *
 * @author SonTT
 */
public class AccountM implements IAccount {

    private TPConnection tpConnection;

    public AccountM() {
    }

    public static Iterator getProducts(String test) {
        String driveString = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        String url = "jdbc:sqlserver://localhost:1433; databasename=tech-pro";
        String username = "sa";
        String password = "fat123456";

        Vector<AccountDetail> accounts = new Vector<AccountDetail>();

        try {
            Class.forName(driveString);
            Connection connection = DriverManager.getConnection(url, username, password);
            Statement stm = connection.createStatement();
            String query = "SELECT * FROM Account";
            ResultSet rs = stm.executeQuery(query);

            if (rs.wasNull()) {
                return null;
            } else {
                while (rs.next()) {
                    AccountDetail a = new AccountDetail(
                            rs.getString(1),
                            rs.getNString(2),
                            rs.getNString(3),
                            rs.getNString(4),
                            rs.getBoolean(5),
                            rs.getDate(6),
                            rs.getInt(7),
                            rs.getString(8),
                            rs.getNString(9),
                            rs.getNString(10),
                            rs.getNString(11),
                            rs.getInt(12),
                            rs.getBoolean(13),
                            rs.getBoolean(14),
                            rs.getDate(15));

                    accounts.addElement(a);
                }

                return accounts.iterator();
            }
        } catch (SQLException ex) {
            Logger.getLogger(ProductM.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ProductM.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    @Override
    public ReturnBool signin(AccountSignin accountSignin) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ReturnBool signup(AccountDetail accountDetail) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<AccountDetail> getAccounts() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ReturnBool addAccount(AccountDetail accountDetail) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ReturnBool editAccount(AccountDetail accountDetail) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ReturnBool deleteAccount(String username) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ReturnBool deleteAccounts(String[] usernames) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<AccountDetail> searchAccount(String keyword) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    private static final Logger LOG = Logger.getLogger(AccountM.class.getName());
}
